﻿<UserControl x:Class="IssueVision.Client.Reports"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:common="clr-namespace:IssueVision.Common;assembly=IssueVision.Common"
    Loaded="UserControl_Loaded"  Unloaded="UserControl_Unloaded"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <UserControl.Resources>
        <common:IssueBrushConverter x:Key="issueBrushConverter"/>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="2*" />
            <RowDefinition Height="3*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Grid.Column="0" x:Name="grid_Charts">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <chartingToolkit:Chart Title="Bug Trends by Month">
                <chartingToolkit:LineSeries Title="Active Bugs"
                                        ItemsSource="{Binding Path=ActiveBugCountByMonth}"
                                        IndependentValueBinding="{Binding Path=Month}"
                                        DependentValueBinding="{Binding Path=Count}" />
                <chartingToolkit:LineSeries Title="Resolved Bugs"
                                        ItemsSource="{Binding Path=ResolvedBugCountByMonth}"
                                        IndependentValueBinding="{Binding Path=Month}"
                                        DependentValueBinding="{Binding Path=Count}" />
            </chartingToolkit:Chart>
            <chartingToolkit:Chart Grid.Column="1" Title="Bug Counts by Priority">
                <chartingToolkit:ColumnSeries Title="Bug Counts"
                                          ItemsSource="{Binding Path=ActiveBugCountByPriority}"
                                          IndependentValueBinding="{Binding Path=Priority}"
                                          DependentValueBinding="{Binding Path=Count}" />
            </chartingToolkit:Chart>
        </Grid>
        <ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 ItemsSource="{Binding Path=AllIssues}" >
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border BorderBrush="Silver" BorderThickness="2"
                                Padding="4" HorizontalAlignment="Stretch"
                                Background="{Binding Converter={StaticResource issueBrushConverter}, 
                                             ValidatesOnNotifyDataErrors=False}" >
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=IssueID, StringFormat='Issue Id: \{0\} ',
                                                      ValidatesOnNotifyDataErrors=False}" />
                                    <TextBlock Text="{Binding Path=Title, ValidatesOnNotifyDataErrors=False}" />
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=Priority, StringFormat='Pri: \{0\} ',
                                                      ValidatesOnNotifyDataErrors=False}" />
                                    <TextBlock Text="{Binding Path=Severity, StringFormat='Sev: \{0\}',
                                                      ValidatesOnNotifyDataErrors=False}" />
                                </StackPanel>
                                <TextBlock TextTrimming="WordEllipsis" TextWrapping="Wrap" MaxHeight="40"
                                           Text="{Binding Path=Description, StringFormat='Description: \{0\}',
                                                  TargetNullValue='No Description', ValidatesOnNotifyDataErrors=False}" />
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        <Button Grid.Row="0" Grid.Column="1"
                VerticalAlignment="Top" HorizontalAlignment="Right" 
                Width="75" Height="23" Margin="4,4,4,0"
                Content="Print Report"
                Command="{Binding Path=PrintReportCommand}"/>
        </Grid>
</UserControl>
